<?php
header("Content-Type:text/html; charset=utf-8");
$rss_url = 'http://echogu.blog.sohu.com/rss';
require_once('./Snoopy/Snoopy.class.php');
$Snoop = new Snoopy();
$Snoop->proxy_host = '203.252.226.215';
$Snoop->proxy_port = '8001';
$Snoop->proxy_port = '8001';
'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12';
$Snoop->fetch($rss_url);
var_dump($Snoop->results);
$contents = $Snoop->results;
//$contents = file_get_contents($rss_url);
//$contents = checkBOM($contents);
//var_dump($contents);
preg_match('#encoding="([^\"]*)"?#',$contents,$matches);
var_dump($matches);
if( 'UTF-8' != $matches[1] ){
  $contents = preg_replace('#encoding="([^\"]*)"?#','encoding="UTF-8"',$contents);
  $contents = mb_convert_encoding ($contents,'UTF-8',$matches[1]);
}
file_put_contents('aaa.txt',$contents);
//$contents = file_get_contents('aaa.txt');
$rss  = simplexml_load_string ($contents,'SimpleXMLElement',LIBXML_NOCDATA);
var_dump($rss);
//$contents = file_get_contents($rss_url);
//$contents = mb_convert_encoding ($contents,'UTF-8','gb2312');
//file_put_contents('aaa.txt',$content);
//echo '中文';
//$content = checkBOM($contents);

//var_dump($contents);

//$contents = checkBOM($contents);
function checkBOM ($contents) {  
 $charset[1] = substr($contents, 0, 1);  
 $charset[2] = substr($contents, 1, 1);  
 $charset[3] = substr($contents, 2, 1);  
 var_dump($charset);
 if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {  
    $rest = substr($contents, 3);  
    //rewrite ($filename, $rest);  
   // return ("<font color=red>BOM found, automatically removed.</font>");  
 } else {
	 //return ("BOM Not Found.");  
 } 
 return $rest;
}
?>